package com.hundredapp.oa.repository;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.hundredapp.oa.dao.GenericDao;
import com.hundredapp.oa.domain.OaRole;

@Repository
public class RoleMangerImpl implements RoleManager{

	@Autowired
	private GenericDao<OaRole, Integer> roleDao;
	
	@Override
	public List<OaRole> findRoleList(String condition) {
		return roleDao.find(condition);
	}
	
	@Override
	public void update(OaRole role) {
		roleDao.modify(role);
		
	}
	
	@Override
	public void delete(int roleid) {
		roleDao.remove(roleDao.findById(roleid));
	}
	
	@Override
	public void add(OaRole role) {
		roleDao.save(role);
	}
	@Override
	public List<OaRole> findRolesByString(String roles){
		List<OaRole> result=new ArrayList<OaRole>();
		for(String id:roles.split(",")){
			result.add(roleDao.findById(Integer.parseInt(id)));
		}
		return result;
	}
	
	@Override
	public OaRole findById(int id) {
		return roleDao.findById(id);
	}

	public GenericDao<OaRole, Integer> getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(GenericDao<OaRole, Integer> roleDao) {
		this.roleDao = roleDao;
	}

	

	

	
}
